<template>
	<view class="container">
		<view class="audit-status">
			<text class="color-base-text font-size-toolbar">商户提示</text>
			<view class="color-sub">{{message}}</view>
		</view>
		<button class="audit-btn color-base-bg" style="bottom:200rpx" type="default" @click="toOpenStep">申请入驻(新)</button>
		<button class="audit-btn color-base-bg" type="default" @click="toOpenInfo">申请入驻</button>
		<loading-cover ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
	import globalConfig from '@/common/js/golbalConfig.js';
	export default {
		data() {
			return {
				member_id: '',
				back: '',
				message: ''
			};
		},
		mixins: [globalConfig],
		onLoad(option) {
			uni.setStorageSync('member_id', option.member_id);
			this.member_id = option.member_id ? option.member_id : '';
			this.back = option.back ? option.back.replace(/\./g, '/') : '';
		},
		onShow() {
			this.getPayInfo();
		},
		methods: {
			toOpenInfo() {
				this.$util.redirectTo('/pages/apply/register', {
					member_id: this.member_id
				})
			},
			toOpenStep(){
				uni.navigateTo({
					url:'/pages/apply/apply_step',
					member_id: this.member_id
				})
			},
			getPayInfo() {
				this.$api.sendRequest({
					url: '/shopapi/login/memberLogin',
					data: {
						member_id: this.member_id
					},
					success: res => {
						if (res.code >= 0 && res.data) {
							uni.setStorageSync('shop_token', res.data.token);
							uni.setStorageSync('site_id', res.data.site_id);
							if (this.back) {
								// this.$util.redirectTo('/' + 'pages/apply/apply_step', {}, 'redirectTo');
								this.$util.redirectTo('/' + 'pages/login/login', {}, 'redirectTo');
							} else {
								this.$util.redirectTo('/pages/index/index', {}, 'reLaunch');
							}
						} else {
							this.message = res.message;
							this.$util.redirectTo('/pages/apply/register', {
								member_id: this.member_id
							})
						}
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					fail: res => {
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				});
			},
		}
	};
</script>

<style lang="scss">
	.container {
		overflow: hidden;
		padding-bottom: 170rpx;

		.audit-status {
			margin-top: 20rpx;
			padding: 40rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			background-color: #fff;

			.qrcode {
				margin: 15rpx auto;
				width: 200rpx;
				height: 200rpx;

				image {
					width: 200rpx;
					height: 200rpx;
				}
			}

			.color-warn {
				color: red;
			}
		}
	}

	.audit-btn {
		position: fixed;
		left: 25px;
		right: 25px;
		bottom: 25px;
		display: block;
		color: #fff;
		z-index: 5;
		border: none;
	}
</style>